package com.loong.game2048.util;

import com.loong.game2048.module.vo.GameDataVo;
import com.loong.game2048.module.vo.Result;
import com.loong.game2048.module.ResultCode;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lyx
 * @date 2020/5/4 17:48
 */
public class ResultUtils {



    public static Result setResult(GameDataVo vo){
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setData(vo);
        switch (vo.getGameState()){
            case 0:
                result.setMsg("操作成功，游戏开始");
                break;
            case 1:
                result.setMsg("操作成功，游戏胜利");
                break;
            case 2:
                result.setMsg("操作成功，游戏继续");
                break;
            case 3:
                result.setMsg("操作成功，游戏结束");
                break;
            default:
                break;
        }
        return result;
    }


    public static String getOpenId(HttpServletRequest request){
        //从token中获取用户openid
        String token = request.getHeader("token");
        String s[] = token.split("\\:");
        if (s.length==1){
            return s[0];
        }
        return s[1];
    }



}
